package se.webbzon.boltzmann.editor.list;

import java.util.Collection;
import java.util.Comparator;

import javax.swing.ComboBoxModel;

public class SortedComboBoxModel<T> extends SortedListModel<T> implements ComboBoxModel<T> {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = 3771217546896153899L;
	
	// The selected item
	private T selectedItem;

	/*============================================================
	Constructors
	============================================================*/

	/** Creates a new sorted combo box model. **/
	public SortedComboBoxModel(Class<T> clazz) {
		super(clazz);
	}

	/** Creates a new sorted combo box model with a given content. **/
	public SortedComboBoxModel(Class<T> clazz, Collection<T> collection) {
		super(clazz,collection);
	}

	/** Creates a new sorted combo box model sorted list model. **/
	public SortedComboBoxModel(Class<T> clazz, Comparator<T> comparator) {
		super(clazz,comparator);
	}

	/** Creates a new sorted combo box model sorted list model with a given content. **/
	public SortedComboBoxModel(	Class<T> clazz, Comparator<T> comparator,
			Collection<T> collection) {
		super(clazz,comparator,collection);
	}
		
	/*============================================================
	Public Methods
	============================================================*/

	@Override public T getSelectedItem() {
		return selectedItem;
	}

	@SuppressWarnings("unchecked")
	@Override public void setSelectedItem(Object anItem) {
		if (anItem == null || !containsElement((T) anItem))
			selectedItem = null;
		else
			selectedItem = (T) anItem;
		fireContentsChanged(this,0,getSize()-1);
	}

}
